package org.catdroid.bcnappsjam.barcelonaparticipa;

import org.catdroid.bcnappsjam.barcelonaparticipa.Adapter.AdapterListReplise;
import org.catdroid.bcnappsjam.barcelonaparticipa.Objectes.Query;
import org.catdroid.bcnappsjam.barcelonaparticipa.Objectes.Replies;

import com.google.gson.Gson;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.TextView;

public class GraphicsActivity extends Activity {
	
	public static final String EXTRA_JSON = "extraJson";
	
	private String dades = "{\"id\":1235,\"title\":\"Que t\u0027agradaria per la propera merçé\",\"replies\":[{\"id\":1,\"text\":\"Més concerts\",\"numberOfVotes\":6,\"selected\":false},{\"id\":2,\"text\":\"Menys bruticia\",\"numberOfVotes\":14,\"selected\":true},{\"id\":3,\"text\":\"Més correfocs\",\"numberOfVotes\":21,\"selected\":false}],\"idApp\":\"123abc\",\"votesTotal\":41}";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.graphics_activity);
		Gson gson = new Gson();
		
		if(getIntent().getExtras().containsKey(EXTRA_JSON)){
			dades = getIntent().getStringExtra(EXTRA_JSON);
		}
		
		Query query = gson.fromJson(dades, Query.class);		
		Replies respostes = query.getReplies();
		
		ListView list = (ListView)findViewById(R.id.listRespostes);
		list.setAdapter(new AdapterListReplise(respostes,query.getVotesTotal(),this));
		
		TextView pregunta = (TextView)findViewById(R.id.txtPregunta);
		pregunta.setText(query.getTitle());
	}







}
